package com.richman.hg;

import java.awt.Color;
import java.awt.EventQueue;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Date;
import java.util.Stack;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.eclipse.swt.browser.Browser;
import org.apache.http.entity.StringEntity;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

import org.json.*;

import java.util.Vector;
import java.util.Comparator;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
//
//import javax.xml.parsers.DocumentBuilder;  
//import javax.xml.parsers.DocumentBuilderFactory;  
//  
//
//
//import org.w3c.dom.Document;  
//import org.w3c.dom.Element;  
//import org.w3c.dom.NodeList;

import com.richman.controller.NegativeRatioClient;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.HGEvent;
import com.richman.ps38.entity.RedcardsRecords;
import com.richman.utils.Common;
import com.richman.utils.SoundThread;
import com.richman.view.BetWindow;

import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

//import org.w3c.dom.Node;

public class HGHttp {

	CloseableHttpClient httpclient = null;
	RequestConfig requestConfig = null;
	HttpClientContext clientContext = null;

	int defaultTimeout = 60 * 1000;

	{

		HttpHost proxy = new HttpHost("127.0.0.1", 1080, "http");

		requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
		requestConfig = RequestConfig.copy(requestConfig).setRedirectsEnabled(false).build();// 禁止重定向 ， 以便获取cookieb18

		// requestConfig =
		// RequestConfig.copy(requestConfig).setProxy(proxy).build();//使用代理

		requestConfig = RequestConfig.copy(requestConfig).setConnectTimeout(defaultTimeout)
				.setConnectionRequestTimeout(defaultTimeout).setSocketTimeout(defaultTimeout).build();// 设置超时
		httpclient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
	}

	String[] blackboxarry = {
			"0400AKHeWb1CT4UHcCiyOFFxUJs9WruPWg2xwTpqC7aOF/G7cVE#xxeTH9qn7gvBN1hODpQyKLUtdcy/gVjxK6YQUmuthzD1rRD5A9buc5roGxhe#J5xbAcO8rvcbfkqJhb4bZWp/5NFsh3QANolZLufCAU8wqwM/zbpaoaJowy5lsfph/T#lMlRTFuxuMBV69L9DJ0qCc4gMpergecSo06izT8HnO#s8lyWpM5YbymrVY7rLMnUY2Yy4xZkFqaUZegb#KaePAdj0dC1DOkZ9ybRxHxfYV3WeA0UYsMZmVY5fSPUN2oHNYZpt1ozpn47xUgPTMj6Y82LrlflYU9iUMb03YzV7IDBIIRtgx5t4CWwXewJB/s4Mwp5btF9#kXk6jWRn9G0Cffid9KqGO3oLohutw1/InDlj2XMuF6OiUfqPLjYdgXmjJkcl5haIlLY6FnWC1qHoGk5NgOHQJG3PEGJQEF/V33vgKI2yAfUMZ5LKFpDFK356A5kn36mAJ3ZTHu23WaFMcpDuPLLCLfgMB41yXjhWeZaU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mTZ7suARIubHa83CDZB6X9z3t5GOE3v/P0fK0Mpi/qz28j7#e7ulr6Q2kPzVR88eWj0RX0JHstg9WGLJ44uwgvmQv7oSpR7vSRRYaqhKKhmTNPWCy4nJzQCugKVOTcKUJixNc9QoXJB6xfRWCqp0tokzUp0K#OKLn0OAhXJ9AFUmoq3MFE1OVZYIN0TiGh2ocxF8rf4jemlekKDk9nbjLKqMlA4FJr4dyXapdkDIJTQkZrrm8#sZ" };

	String chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";

	private int statusCode = -1;

	Vector<Long> lastTenRequestTime = new Vector<Long>();
	long avgRequestTime = 0;
	boolean bcalcRequestTime = true;
	boolean bneedChangeLine = false;

	long lastChangeLineTime = 0;

	String strCookies = "";
	
	String uid = "";
	String ver = "";

	int requestFailTimes = 0;
	long lastFailtime = 0;

	boolean isNeedRelogin = false;

	public boolean isInRelogin = false;

	String ADDRESS = "";
	String OLDADDRESS = "";
	String ACCOUNT = "";
	String PWD = "";
	String SECURITYCODE = "";

	String user_id = "";
	String mtype = "3";
	String cid = "";
	int time_zone = 0;

	boolean bLogin = false;

	String oldSiteAddress = "";

	Vector<String> showLeagueName = new Vector<String>();

	private ReadWriteLock lockeFinalEventsDetails = new ReentrantReadWriteLock();

	private ReadWriteLock lockeSuccessTime = new ReentrantReadWriteLock();

	private ReadWriteLock inplaydxqgameslock = new ReentrantReadWriteLock();

	public Vector<String[]> finalEventDetailsVec = new Vector<String[]>();

	public String successTime = "";

	public long canLoginTime;
	public long checkOnlineTime;

	public int getStatusCode() {

		return statusCode;
	}

	public String getuser_id() {
		return user_id;
	}

	// 1成功 -1登录失败, -2维护 , -3账号异常 , -4密码不正确 , 2抓取成功, 3抓取失败
	public void updateStatusCode(int i) {

		String accounttype = "";
		if (mtype.equals("1")) {
			accounttype = "A盘	";
		} else if (mtype.equals("2")) {
			accounttype = "B盘";
		} else if (mtype.equals("3")) {
			accounttype = "C盘";
		} else if (mtype.equals("4")) {
			accounttype = "D盘";
		}

		if (i == -2) {
			canLoginTime = System.currentTimeMillis() + 5 * 60 * 1000;

			NegativeRatioClient.mainWnd.updateMainWndHGStatusText(0, "网站维护中");

		}

		if (i == 1) {
			checkOnlineTime = System.currentTimeMillis() + 30 * 1000;

			NegativeRatioClient.mainWnd.updateMainWndHGStatusText(1, ACCOUNT + "   " + accounttype + "在线");

		}

		if (statusCode != 1) {

			NegativeRatioClient.mainWnd.updateMainWndHGStatusText(0, ACCOUNT + "   " + "登录中");

			NegativeRatioClient.showtext += Common.getcurrentTimeStr() + ":皇冠登陆中...\n";
		}

		if (statusCode != 1 && i == 1) {

			NegativeRatioClient.mainWnd.updateMainWndHGStatusText(1, ACCOUNT + "   " + accounttype + "在线");
			NegativeRatioClient.showtext += Common.getcurrentTimeStr() + ":皇冠登录成功\n";
		}

		if (i == -1) {

			NegativeRatioClient.mainWnd.updateMainWndHGStatusText(0, "掉线,重新登录中");

			// 发出声音
			if (SoundThread.inPlay == false) {
				SoundThread st = new SoundThread();
				SoundThread.status = 2;
				st.start();
			}
		}
		
		if(i==-1||i==-3||i==-4) {
			if(ACCOUNT.equals(NegativeRatioClient.betCtrMng.getinUsedAccountName()))
				NegativeRatioClient.betCtrMng.useNextAccount();
		}

		if (statusCode != i) {
			System.out.println("皇冠HTTP状态更新" + ACCOUNT + "  update hg_statusCode from " + Integer.toString(statusCode)
					+ " to " + Integer.toString(i));
		}

		NegativeRatioClient.mainWnd.updateHGAccountStatus(ACCOUNT, statusCode);

		statusCode = i;

	}

	public long getCanLoginTime() {
		return canLoginTime;
	}

	public long getCheckOnlineTime() {
		return checkOnlineTime;
	}

	public void initShowLeagueName() {
		showLeagueName.add("德国 - 德甲");
		showLeagueName.add("欧足联 - 冠军联赛");
		showLeagueName.add("西班牙 - 西甲");
		showLeagueName.add("意大利 - 甲级联赛");
		showLeagueName.add("法国 - 甲级联赛");
		showLeagueName.add("英格兰 - 超级联赛");
		showLeagueName.add("欧足联 - 欧罗巴联赛");
	}

	public void clearuser_id() {
		user_id = "";
	}

	public void setAddress(String address) {
		ADDRESS = address;
	}

	public boolean isInShowLeagueName(String str) {
		boolean in = false;

		for (int i = 0; i < showLeagueName.size(); i++) {
			if (showLeagueName.elementAt(i).contains(str)) {
				in = true;
				break;
			}
		}

		return in;
	}

	public void setGrabStext(String str) {

		SimpleDateFormat df = new SimpleDateFormat("MM-dd HH:mm:ss");// 设置日期格式

		String timeStr = df.format(System.currentTimeMillis());

		// gamedetailswnd.setStateText(timeStr + ":" + str);

	}

	public void setGrabColor(Color cr) {

		// gamedetailswnd.setStateColor(cr);

	}

	public void copyTofinalEventsDetails() {

		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");// 设置日期格式

		long currentTimeL = System.currentTimeMillis();

		String currentTime = df.format(currentTimeL);

		lockeFinalEventsDetails.writeLock().lock();

		if (finalEventDetailsVec.size() != 0) {
			finalEventDetailsVec.clear();
		}

		// for(int i = 0; i < eventDetailsVec.size(); i++ ){
		// finalEventDetailsVec.add(eventDetailsVec.elementAt(i).clone());
		// }

		lockeFinalEventsDetails.writeLock().unlock();

		lockeSuccessTime.writeLock().lock();
		successTime = currentTime + " 成功";
		lockeSuccessTime.writeLock().unlock();
	}

	public Vector<String[]> getFinalEventsDetails() {
		Vector<String[]> vec = new Vector<String[]>();
		lockeFinalEventsDetails.readLock().lock();

		for (int i = 0; i < finalEventDetailsVec.size(); i++) {
			vec.add(finalEventDetailsVec.elementAt(i).clone());
		}

		// vec = (Vector<String[]>)finalEventDetailsVec.clone();
		lockeFinalEventsDetails.readLock().unlock();
		return vec;
	}

	public String getSuccessTime() {
		String successTimetmp = "";
		lockeSuccessTime.readLock().lock();
		successTimetmp = successTime;
		lockeSuccessTime.readLock().unlock();
		return successTimetmp;
	}

	public String getAccount() {
		return ACCOUNT;
	}

	public boolean islogin() {
		return bLogin;
	}

	public void setIslogin(boolean b) {
		bLogin = b;
	}

	public void setLoginParams(String address, String account, String pwd) {
		ADDRESS = address;
		OLDADDRESS = address;
		ACCOUNT = account;
		PWD = pwd;
	}

	public int login() {// 1成功 -1登录失败, -2维护 , -3账号异常, -4密码不正确

    	try{
    		ADDRESS = OLDADDRESS;    		
        	String loginLine = ADDRESS;
        	
        	List<NameValuePair> detectionParams = new ArrayList<NameValuePair>();
        	detectionParams.add(new BasicNameValuePair("detection", "Y"));
        	
        	String res = doPost(loginLine, detectionParams, "");
        	
        	if(res==null) {
        		res = doPost(loginLine, detectionParams, "");
        	}
        	
        	if(res.contains("top.ver")) {
        		int ps = res.indexOf("top.ver") + 7;
        		ps = res.indexOf("'",ps) + 1;
	        	int pe = res.indexOf("'",ps);
	        	ver = res.substring(ps, pe);
	        	if(ver.contains("")) {
	        		//ver = new  String(ver.getBytes("ISO-8859-1"), "utf-8");
	        		ver = ver.replace("", "%08");
	        	}
	        	//https://hga030.com/transform.php?
	        	loginLine = ADDRESS + "transform.php?ver=" + ver;
		        int arrayindex =(int)(Math.random()*4);
		        String blackbox = blackboxarry[arrayindex];
		        StringBuilder strBuilder = new StringBuilder(blackbox);
		        for(int i = 26; i < 34; i++){
		        	strBuilder.setCharAt(i, chars.charAt((int)(Math.random()*62)));
		        }
		        blackbox = strBuilder.toString();
	        	List<NameValuePair> loginParams = new ArrayList<NameValuePair>();
	        	loginParams.add(new BasicNameValuePair("p", "chk_login"));
	        	loginParams.add(new BasicNameValuePair("langx", "zh-cn"));
	        	loginParams.add(new BasicNameValuePair("ver", ver));
	        	loginParams.add(new BasicNameValuePair("username", ACCOUNT));
	        	loginParams.add(new BasicNameValuePair("password", PWD));
	        	loginParams.add(new BasicNameValuePair("app", "N"));
	        	loginParams.add(new BasicNameValuePair("auto", "GIICFD"));
	        	loginParams.add(new BasicNameValuePair("blackbox", blackbox));
	        	res = doPost(loginLine, loginParams, "");
	        	
	        	if(res==null) {
	        		res = doPost(loginLine, loginParams, "");
	        	}
	        	
	        	if(res.contains("è")){
	        		res = new  String(res.getBytes("ISO-8859-1"), "utf-8");
	        	}
	        	
	        	if(res.contains("code_message")) {
//	        		res = res.replace("<code_message>", "<code_message id='4.175'  hasEC=\"Y\">");
//	        		res = res.replace("<msg>", "<code_message id='4.275'>");
//	        		res = res.replace("</msg>", "</code_message>");
	            	Document doc = Jsoup.parse(res);
	            	Element element = doc.select("status").first();
	           	 	if(element.html().contains("200")) {
	           	 		
	           	 		Element element1 = doc.select("uid").first();
	           	 		uid = element1.html();
	           	 		
	           	 		String username = doc.select("username").first().html();
	           	 		
	           	 		List<NameValuePair> checkLoginDomainParams = new ArrayList<NameValuePair>();
	           	 		checkLoginDomainParams.add(new BasicNameValuePair("p", "check_login_domain"));
	           	 		checkLoginDomainParams.add(new BasicNameValuePair("ver", ver));
	           	 		checkLoginDomainParams.add(new BasicNameValuePair("username", username));
	           	 		checkLoginDomainParams.add(new BasicNameValuePair("uid", uid));
	           	 		checkLoginDomainParams.add(new BasicNameValuePair("langx", "zh-cn"));
	           	 		checkLoginDomainParams.add(new BasicNameValuePair("code", "663"));
	           	 		
		           	 	res = doPost(loginLine, checkLoginDomainParams, "");
			        	
			        	if(res==null) {
			        		res = doPost(loginLine, checkLoginDomainParams, "");
			        	}
			        	
			        	if(res.contains("è")){
			        		res = new  String(res.getBytes("ISO-8859-1"), "utf-8");
			        	}
	           	 		
			        	doc = Jsoup.parse(res);
			        	
			        	element1 = doc.select("new_domain").first();
			        	if(!element1.html().equals("no") && !element1.html().equals("")) {
			        		ADDRESS = "https://" + element1.html() + "/";
			        	}
	           	 		System.out.println("ADDRESS");
	           	 		
	           	 		updateStatusCode(1);
	           	 		return 1;	           	 		
	           	 	}
	        	}
        	}
    	}catch(Exception e){
    		e.printStackTrace();
    	}    	
    	updateStatusCode(-1);    	
    	return -1;
		
		
//		try {
//
//			ADDRESS = OLDADDRESS;
//			
//			String loginLine = ADDRESS;
//
//			String res = doGet(loginLine, "", "");
//
//			if (res.contains("è")) {
//				res = new String(res.getBytes("ISO-8859-1"), "utf-8");
//			}
//
//			System.out.println("address" + ADDRESS + "        account:" + ACCOUNT + "    pwd:" + PWD);
//
//			if (res != null && res.contains("Welcome")) {
//				res = doGet(loginLine + "app/member/", "", "");
//
//				if (res.contains("è")) {
//					res = new String(res.getBytes("ISO-8859-1"), "utf-8");
//				}
//
//				if (res.contains("chgURL_new_domain")) {
//
//					// int pstmp1 = res.indexOf("chgURL_domain");
//					// pstmp1 = res.indexOf("'", pstmp1) + 1;
//					// int petmp1 = res.indexOf("'",pstmp1);
//					//
//					// oldSiteAddress = "http://" + res.substring(pstmp1, petmp1) + "/";
//
//					res = doGet(ADDRESS + "iovation/vindex.php", "", "");
//
//					if (res.contains("è")) {
//						res = new String(res.getBytes("ISO-8859-1"), "utf-8");
//					}
//
//					List<NameValuePair> params = new ArrayList<NameValuePair>();
//
//					params.add(new BasicNameValuePair("username", ACCOUNT));
//					params.add(new BasicNameValuePair("passwords", PWD));
//					params.add(new BasicNameValuePair("auto", "CFADCB"));
//					params.add(new BasicNameValuePair("langx", "zh-cn"));
//
//					int arrayindex = (int) (Math.random() * 4);
//					String blackbox = blackboxarry[arrayindex];
//					StringBuilder strBuilder = new StringBuilder(blackbox);
//					for (int i = 26; i < 34; i++) {
//						strBuilder.setCharAt(i, chars.charAt((int) (Math.random() * 62)));
//					}
//					blackbox = strBuilder.toString();
//
//					params.add(new BasicNameValuePair("blackbox", blackbox));
//					res = doPost(ADDRESS + "app/member/new_login.php", params, "");
//
//					if (res.contains("è")) {
//						res = new String(res.getBytes("ISO-8859-1"), "utf-8");
//					}
//
//					if (null != res && res.contains("200|100")) {
//
//						int ps = res.indexOf("||") + 2;
//						int pe = res.indexOf("|", ps);
//
//						String loginfo[] = res.split("\\|");
//
//						user_id = loginfo[3];
//
//						mtype = loginfo[4];
//
//						// user_id = res.substring(ps, pe);
//
//						updateStatusCode(1);
//						
//						getAddress();
//
//						return 1;
//
//					}
//
//				}
//
//			}
//
//			if (res.contains("System Maintenance") || res.contains("maintain_time") || res.contains("请稍后再尝试登入")) {
//
//				updateStatusCode(-2);
//
//				return -2;
//			}
//
//			if (res.contains("请联系您的上线")) {
//
//				updateStatusCode(-3);
//
//				return -3;
//			}
//
//			if (res.contains("密码不正确")) {
//				updateStatusCode(-4);
//
//				return -4;
//			}
//
//			System.out.println("登录失败:");
//
//			System.out.println(res);
//
//		} catch (Exception e) {
//			e.printStackTrace();
//
//		}
//
//		updateStatusCode(-1);
//
//		return -1;
	}

    public void getAddress() {
    	//https://hga038.com/app/member/FT_index.php?uid=g00tp64c4m23656917l278478b0&langx=zh-cn&mtype=3&news_mem=Y&r=32392543
    		
    	String url = ADDRESS + "app/member/FT_index.php?uid=" + user_id + "&langx=zh-cn&mtype=" + mtype + "&news_mem=Y&r=32392543";
    	String res = doGet(url, "", "");
    	if(res==null)
    	{
    		res = doGet(url, "", "");
    	}
    	Document doc = Jsoup.parse(res);
   	 	Element form = doc.getElementById("newdomain");
   	 	if(form!=null) {
   	 		ADDRESS =  form.attr("action") + "/";
   	 	}
    }
	
	public String getmtype() {
		return mtype;
	}

	public CloseableHttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException {

		long time1 = System.currentTimeMillis();
		long time2 = System.currentTimeMillis();

		CloseableHttpResponse response;

		SimpleDateFormat dfsec = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		try {
			Thread.sleep(100);
			// Thread.sleep(1200);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// System.out.println("excecute time:" + dfsec.format(time1));

		try {
			response = httpclient.execute(request);
			time2 = System.currentTimeMillis();
			calcRequestAveTime(time2 - time1);

		} catch (Exception e) {

			time2 = System.currentTimeMillis();
			calcRequestAveTime(time2 - time1);

			throw e;
		}

		return response;

	}

	public String doGet(String url, String cookies, String referUrl) {

		try {
			// 创建httpget.
			HttpGet httpget = new HttpGet(url);

			if (cookies != "") {
				httpget.addHeader("Cookie", cookies);
			}
			httpget.addHeader("Accept-Encoding", "Accept-Encoding: gzip, deflate, sdch");
			httpget.addHeader("Accept-Language", "Accept-Language: zh-CN,zh;q=0.8");
			httpget.addHeader("Connection", "keep-alive");
			httpget.addHeader("Upgrade-Insecure-Requests", "1");
			httpget.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
			//

			if (referUrl != "") {
				httpget.addHeader("Referer", referUrl);

			}

			httpget.addHeader("User-Agent",
					"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36");
			// System.out.println("executing request " + httpget.getURI());

			// 设置超时

			// HttpHost proxy = new HttpHost("127.0.0.1", 1080, "http");
			//
			// RequestConfig requestConfigtmp =
			// RequestConfig.custom().setSocketTimeout(defaultTimeout).setConnectTimeout(defaultTimeout).build();
			// requestConfigtmp=
			// RequestConfig.copy(requestConfigtmp).setProxy(proxy).build();
			// httpget.setConfig(requestConfigtmp);

			// 执行get请求.
			CloseableHttpResponse response = execute(httpget);

			String statusLine = response.getStatusLine().toString();
			if (statusLine.indexOf("200 OK") == -1) {
				// System.out.println(statusLine);
			}

			try {
				setCookie(response);
				// System.out.println("设置cookie:" + strCookies);

				if (response.getStatusLine().toString().indexOf("302 Found") > 0) {
					return response.getFirstHeader("Location").getValue();
				}
				HttpEntity entity = response.getEntity();

				String res = EntityUtils.toString(entity);

				if (res != null && res.length() > 0) {
					// System.out.println(res);

					if (res.contains("logout_warn")) {
						updateStatusCode(-1);
					}

					return res;
				}
			} finally {
				httpget.releaseConnection();
				response.close();
			}

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	/** 以utf-8形式读取 */
	public String doPost(String url, List<NameValuePair> formparams, String cookies) {
		return doPost(url, formparams, "UTF-8", cookies);
	}

	public String doPost(String url, List<NameValuePair> formparams, String charset, String cookies) {

		// 创建httppost

		try {

			HttpPost httppost = new HttpPost(url);

			/*
			 * if(url.contains("get_today_ft_league_wager.php")){
			 * httppost.addHeader("Cookie", strCookies); }
			 */

			// httppost.addHeader("Cookie", cookies);
			// httppost.addHeader("Accept-Encoding","Accept-Encoding: gzip, deflate, sdch");
			// httppost.addHeader("x-requested-with","XMLHttpRequest");
			
			httppost.addHeader("Cookie", "cu=Y; protocolstr=https; test=init");
			
			httppost.addHeader("Accept-Language", "Accept-Language: zh-CN");
			httppost.addHeader("Accept", "application/json, text/javascript, */*; q=0.01");
			httppost.addHeader("Accept-Encoding", "gzip, deflate");
			httppost.addHeader("Connection", "keep-alive");
			httppost.addHeader("Cache-Control", "max-age=0");
			
	        String Host = ADDRESS.replace("https://", "");
	        Host = Host.replace("/", "");
			
	        httppost.addHeader("Host",Host);
	        httppost.addHeader("Origin","https://"+Host);
	        httppost.addHeader("Referer",ADDRESS);
			
			httppost.addHeader("User-Agent",
					"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36");

			UrlEncodedFormEntity uefEntity;

			uefEntity = new UrlEncodedFormEntity(formparams, charset);
			httppost.setEntity(uefEntity);

			// HttpHost proxy = new HttpHost("127.0.0.1", 1080, "http");
			//
			//
			//
			//
			//
			// RequestConfig requestConfigtmp =
			// RequestConfig.custom().setSocketTimeout(defaultTimeout).setConnectTimeout(defaultTimeout).build();
			// requestConfigtmp=
			// RequestConfig.copy(requestConfigtmp).setProxy(proxy).build();
			// httppost.setConfig(requestConfigtmp);

			CloseableHttpResponse response = execute(httppost);
			try {
				// 打印响应状态
				setCookie(response);
				// System.out.println("设置cookie:" + strCookies);
				if (response.getStatusLine().toString().indexOf("302 Found") > 0) {
					String location = response.getFirstHeader("Location").getValue();
					// System.out.println(response.getStatusLine());

					if (location != null) {
						return location;
					}
				}

				// Header headers[] = response.getHeaders("Content-Type");

				HttpEntity entity = response.getEntity();

				String res = "";

				if (url.contains("get_today_ft_league_wager.php")
						|| url.contains("app/ft/get_today_ft_allbets_wager.php")) {
					res = new String(EntityUtils.toString(entity).getBytes("ISO-8859-1"), "UTF-8");
				} else {
					res = EntityUtils.toString(entity);
				}

				if (res != null && res.length() > 0) {

					if (res.contains("logout_warn")) {
						updateStatusCode(-1);
					}

					// System.out.println(res);
					return res;
				}

			} finally {
				httppost.releaseConnection();
				response.close();
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public String setCookie(CloseableHttpResponse httpResponse) {
		// strCookies = "";
		// System.out.println("----setCookieStore");
		Header headers[] = httpResponse.getHeaders("Set-Cookie");
		if (headers == null || headers.length == 0) {
			// System.out.println("----there are no cookies");
			return null;
		}

		String cookie = "";
		for (int i = 0; i < headers.length; i++) {
			cookie += headers[i].getValue();
			if (i != headers.length - 1) {
				cookie += ";";
			}
		}
		String cookies[] = cookie.split(";");

		for (String c : cookies) {
			if (c.indexOf("path=") != -1 || c.indexOf("expires=") != -1 || c.indexOf("domain=") != -1
					|| c.indexOf("HttpOnly") != -1)
				continue;
			strCookies += c;
			strCookies += ";";
		}
		// System.out.println("----setCookieStore success");

		return strCookies;
	}

	public synchronized void calcRequestAveTime(long requestTime) {

		if (bcalcRequestTime == true) {

			// requestCount++;

			long totalReqeustTime = 0;

			lastTenRequestTime.add(requestTime);

			while (lastTenRequestTime.size() > 10) {
				lastTenRequestTime.remove(0);
			}

			if (lastTenRequestTime.size() == 10) {
				for (int i = 0; i < lastTenRequestTime.size(); i++) {
					totalReqeustTime += lastTenRequestTime.elementAt(i);
				}
				avgRequestTime = totalReqeustTime / lastTenRequestTime.size();

				// System.out.printf("[迪斯尼会员]平均请求时间:%d\n", avgRequestTime);

				long currentTime = System.currentTimeMillis();

				long passTime = currentTime - lastChangeLineTime;

				if (avgRequestTime >= 500 && passTime >= 90 * 1000) {
					// setisNeedChangeLine(true);
					lastChangeLineTime = currentTime;
				}

			}

		}

	}

	public void addFailsTimes() {

		System.out.println("add failed times");

		long currentTime = System.currentTimeMillis();

		if (((currentTime - lastFailtime) < 40 * 1000) || (lastFailtime == 0)) {
			requestFailTimes++;

			lastFailtime = currentTime;

			if (requestFailTimes >= 8) {
				System.out.println("request fail times big than 4");
				setIsNeedRelogin(true);
				requestFailTimes = 0;

			}

		} else {
			requestFailTimes = 1;
			lastFailtime = currentTime;
		}
	}

	public void setIsNeedRelogin(boolean flag) {

		System.out.println("set need relogin");

		isNeedRelogin = flag;
		requestFailTimes = 0;

		updateStatusCode(-1);

	}

	public boolean getIsNeedRelogin() {
		return isNeedRelogin;
	}

	public void checkIsOnline() {

		try {
			
        	List<NameValuePair> memberDataParams = new ArrayList<NameValuePair>();
        	memberDataParams.add(new BasicNameValuePair("p", "get_member_data"));
        	memberDataParams.add(new BasicNameValuePair("uid", uid));
        	memberDataParams.add(new BasicNameValuePair("ver", ver));
        	memberDataParams.add(new BasicNameValuePair("langx", "zh-cn"));
        	memberDataParams.add(new BasicNameValuePair("change", "credit"));
        	String url  = ADDRESS + "transform.php?ver=" + ver;
        	String res = doPost(url, memberDataParams, "");
        	if(res==null) {
        		res = doPost(url, memberDataParams, "");
        	}
        	
        	if(res==null) {
        		addFailsTimes();
        		return;
        	}
        	
        	if(res.contains("maxcredit")) {
        		Document doc = Jsoup.parse(res);
				String balance = doc.selectFirst("maxcredit").ownText();
				NegativeRatioClient.mainWnd.updateHGAccountBalance(ACCOUNT, balance);
				updateStatusCode(1);
        	}else {
        		updateStatusCode(-1);
        	}
        	


		} catch (Exception e) {
			e.printStackTrace();

			if (e.toString().contains("timed out")) {
				Common.logOut("hg 取余额失败，超时，不需要重新登录");
				return;
			}

			updateStatusCode(-1);
		}

	}
	
	
	
    public boolean getDanshiPankouAndDaxiao() {
    	try {
    		
    		
    		 Vector<HGEvent> HGEvents = new Vector<HGEvent>();
    		
    		//https://m588.hga030.com/transform.php?ver=2021-07-21-04en10f7b-3ed5-ad58-0720-872ae5576be7
    		String url  = ADDRESS + "transform.php?ver=" + ver;
    		List<NameValuePair> leagueListParams = new ArrayList<NameValuePair>();
    		leagueListParams.add(new BasicNameValuePair("p", "get_league_list_All"));
    		leagueListParams.add(new BasicNameValuePair("uid", uid));
    		leagueListParams.add(new BasicNameValuePair("ver", ver));
    		leagueListParams.add(new BasicNameValuePair("langx", "zh-cn"));
    		leagueListParams.add(new BasicNameValuePair("gtype", "FT"));
    		leagueListParams.add(new BasicNameValuePair("FS", "N"));
    		leagueListParams.add(new BasicNameValuePair("showtype", "ft"));
    		leagueListParams.add(new BasicNameValuePair("date", "0"));
    		leagueListParams.add(new BasicNameValuePair("nocp", "N"));
    		
    		String res = doPost(url, leagueListParams, "");
    		if(res==null) {
    			res = doPost(url, leagueListParams, "");
    		}
    		if(res==null) {
   	 			return false;
   	 		}
    		
    		if(res.contains("get_league_list_All")) {
    			if(res.contains("lid")) {
        			Document doc = Jsoup.parse(res);
                	Element element = doc.select("lid").first();
               	 	String lid = element.html();
               	 	if(lid.length()>0) {
               	 		List<NameValuePair> getGameListParams = new ArrayList<NameValuePair>();
               	 		getGameListParams.add(new BasicNameValuePair("p", "get_game_list"));
               	 		getGameListParams.add(new BasicNameValuePair("ver", ver));
               	 		getGameListParams.add(new BasicNameValuePair("uid", uid));
               	 		getGameListParams.add(new BasicNameValuePair("langx", "zh-cn"));
               	 		getGameListParams.add(new BasicNameValuePair("p3type", ""));
               	 		getGameListParams.add(new BasicNameValuePair("date", "0"));
               	 		getGameListParams.add(new BasicNameValuePair("gtype", "ft"));
               	 		getGameListParams.add(new BasicNameValuePair("showtype", "today"));
               	 		getGameListParams.add(new BasicNameValuePair("rtype", "r"));
               	 		getGameListParams.add(new BasicNameValuePair("ltype", "3"));
               	 		getGameListParams.add(new BasicNameValuePair("lid", lid));
               	 		getGameListParams.add(new BasicNameValuePair("action", "clickCoupon"));
               	 		getGameListParams.add(new BasicNameValuePair("sorttype", "L"));
               	 		getGameListParams.add(new BasicNameValuePair("specialClick", ""));
               	 		//getGameListParams.add(new BasicNameValuePair("target", ""));
               	 		getGameListParams.add(new BasicNameValuePair("isFantasy", "N"));
               	 		getGameListParams.add(new BasicNameValuePair("ts", Long.toString(System.currentTimeMillis())));
               	 		
               	 		res = doPost(url, getGameListParams,"");
               	 		if(res==null) {
               	 			res = doPost(url, getGameListParams,"");
               	 		}
	               	 	if(res==null) {
	               	 		addFailsTimes();
	           	 			return false;
	           	 		}
	               	 	if(res.contains("è")||res.contains("é")){
	    	        		res = new  String(res.getBytes("ISO-8859-1"), "utf-8");
	    	        	}
	               	 	
	               	 	Document docgames = Jsoup.parse(res);
	               	 	int gameCount = docgames.select("ec").size();
	                	//Elements games = //doc.getElementsByTag("game");//doc.select("game");
	                	SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	                	
	                	//for(Element game: games) {
	                	Vector<String> filterGames = new Vector<String>();


	                	
	                	for(int j = 0; j < gameCount;j++) {
	                		Element game = docgames.select("ec").get(j);
	                		String ecid = game.getElementsByTag("ECID").first().ownText();//是之前的eventID吗？
//	                		if(!filterGames.contains(ecid)) {
//	                			continue;
//	                		}
	                		String year = game.getElementsByTag("SYSTIME").first().ownText().split("-")[0];
	                		
	            			HGEvent hgEvent = new HGEvent();
	            			hgEvent.eventId = ecid;
	            			hgEvent.gid = game.getElementsByTag("GID").first().ownText();
	            			hgEvent.leagueName = game.getElementsByTag("LEAGUE").first().ownText();
	            			hgEvent.homeTeam = game.getElementsByTag("TEAM_H").first().ownText().replace(" [中]", "");
	            			hgEvent.awayTeam = game.getElementsByTag("TEAM_C").first().ownText().replace(" [中]", "");
	            			String datetime = game.getElementsByTag("DATETIME").first().ownText();
	            			
	                		if(datetime.contains("a")){
	                			datetime = datetime.replace("a", "");
	                			datetime = year + "-" + datetime;
	                			
	                			java.util.Date startTimeDate = dfmin.parse(datetime);
	                			
	                			Calendar startTime = Calendar.getInstance();  
	                			startTime.setTime(startTimeDate);
	                			startTime.add(Calendar.HOUR_OF_DAY, 12);
	                			
	                			datetime = dfmin.format(startTime.getTimeInMillis());
	                		}
	                		
	                		if(datetime.contains("p")){
	                			datetime = datetime.replace("p", "");
	                			datetime = year + "-" + datetime;

	                			java.util.Date startTimeDate = dfmin.parse(datetime);
	                			
	                			Calendar startTime = Calendar.getInstance();  
	                			startTime.setTime(startTimeDate);
	                			//startTime.add(Calendar.DAY_OF_MONTH, 1);
	                			
	                			if(startTime.getTime().getHours()==12){
	                				startTime.add(Calendar.HOUR_OF_DAY, 12);
	                			}else{
	                				startTime.add(Calendar.DAY_OF_MONTH, 1);
	                			}
	                			
	                			
	                			datetime = dfmin.format(startTime.getTimeInMillis());
	                			
	                		}
	            			
	            			hgEvent.eventTime = datetime;

	            			hgEvent.gnumh = game.getElementsByTag("GNUM_H").first().ownText();
	            			hgEvent.gnumc = game.getElementsByTag("GNUM_C").first().ownText();
	            			String strong = game.getElementsByTag("STRONG").first().ownText();
	            			String pankou = game.getElementsByTag("RATIO_R").first().ownText().replace(" ", "");
	            			hgEvent.wholeRQPPankou = Common.pankouStr(strong + pankou);
	            			hgEvent.wholeRQPPankouUp = game.getElementsByTag("IOR_RH").first().ownText();
	            			hgEvent.wholeRQPPankouDown = game.getElementsByTag("IOR_RC").first().ownText();
	            			hgEvent.strong = strong;
	            			
	            			String o = game.getElementsByTag("RATIO_OUO").first().ownText();
        					hgEvent.wholeDXPPankou = Common.pankouStr(o);
	            			hgEvent.wholeDXPPankouUp = game.getElementsByTag("IOR_OUC").first().ownText();
	            			hgEvent.wholeDXPPankouDown = game.getElementsByTag("IOR_OUH").first().ownText();
	            			
	            			HGEvents.add(hgEvent);
	            			
	                	}
	                	
               	
               	 	}
    			}
    			
    			if(HGEvents.size()>0) {
    				//todo 更新betlog和betres
    				NegativeRatioClient.betCtrMng.updateDanshiPankouAndDaxiao(HGEvents);
    				Common.logOut("更新单式盘口和大小");
    				
    			}

    			return true;
    		}
    		addFailsTimes();
    		return false;
    	}catch(Exception e) {
    		e.printStackTrace();
    		addFailsTimes();
    	}
    	
    	return false;
    }
	

	public boolean getInplaybet() {

		try {

			String res = "";

			// String referuri = ADDRESS + "app/member/FT_browse/index.php?rtype=re&uid=" +
			// user_id + "&langx=zh-cn&mtype=3&showtype=&hot_game=";
			//
			// res = doGet(referuri, "", "");
			//
			// if(res == null) {
			// res = doGet(referuri, "", "");
			// }
			//
			//
			res = doGet(ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re" + "&langx=zh-cn"
					+ "&mtype=" + mtype + "&page_no=0" + "&league_id=&hot_game=" + "&isie11=%27N%27", "", "");

			if (res == null) {

				Thread.currentThread();
				Thread.sleep(4 * 1000);

				res = doGet(
						ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re" + "&langx=zh-cn"
								+ "&mtype=" + mtype + "&page_no=0" + "&league_id=&hot_game=" + "&isie11=%27N%27",
						"", "");
			}

			if (res == null) {
				addFailsTimes();
				return false;
			}

			// System.out.println(res);

			if (res.contains("logout_warn")) {

				System.out.println("inplay contains logout_warn");

				setIsNeedRelogin(true);

				return false;

			}

			HGManager.redcardsRecords.clear();

			String previousgame = "";

			String currentgame = "";

			int priority = -1;

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式

			long currentTimeL = System.currentTimeMillis();

			String currentTime = df.format(currentTimeL);

			if (null != res && res.contains("g([")) {

				// 解析工作 第一页
				// res = bala...

				if (res.contains("è")) {
					res = new String(res.getBytes("ISO-8859-1"), "utf-8");
				}

				// int ps = res.indexOf("_.gamount=");
				int ps = res.indexOf("today_gmt");
				ps = res.indexOf("'", ps) + 1;
				int pe = res.indexOf("'", ps);

				String year = res.substring(ps, pe).split("-")[0];

				// ps = res.indexOf(arg0)

				ps = res.indexOf("g([") + 3;
				pe = res.indexOf(";", ps);

				// System.out.println(res);

				SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd HH:mm");

				while (ps != -1) {

					boolean bignore = false;

					String[] details = res.substring(ps, pe).split(",");

					if (details.length < 57) {
						System.out.println("fuck length small than 57");
					}

					String eventid = details[50];
					eventid = eventid.replace("'", "");

					currentgame = eventid;

					// if(!currentgame.equals(previousgame)){
					// priority = 1;
					// }else{
					// priority = priority + 1;
					// bignore = true;
					// }

					String redcardh = details[29].replace("'", "");
					String redcardc = details[30].replace("'", "");

					String scoreh = details[18];
					scoreh = scoreh.replace("'", "");

					String scorec = details[19];
					scorec = scorec.replace("'", "");

					String timer = details[48];
					timer = timer.replace("'", "");

					timer = timer.replace("^", " ");

					if (timer.contains("半场")) {
						timer = "半场";
					}

					String gid = details[0]; // 标识一个盘口的
					gid = gid.replace("'", "");

					String datetime = details[1];
					datetime = datetime.replace("'", "");
					datetime = datetime.replace("<br>", " ");

					if (datetime.contains("半场")) {
						datetime = "半场";
					}

					String league = details[2];
					league = league.replace("'", "");

					if (league.contains("-附加赛")) {
						league = league.replace("-附加赛", "");
					}

					if (league.contains("特别投注")) {
						bignore = true;
					}

					String gnumh = details[3];
					gnumh = gnumh.replace("'", "");

					String gnumc = details[4];
					gnumc = gnumc.replace("'", "");

					String teamh = details[5];
					teamh = teamh.replace("'", "");
					teamh = teamh.replace(" [中]", "");

					if (teamh.contains("角球数") || teamh.contains("罚牌数")) {

						bignore = true;
					}

					String teamc = details[6];
					teamc = teamc.replace("'", "");

					if (teamc.contains("纽卡斯尔")) {
						System.out.println("fuck");
					}

					// 全场
					String strong = details[7];
					strong = strong.replace("'", "");

					String pankou = details[8];
					pankou = pankou.replace("'", "");

					String rh = details[9];
					rh = rh.replace("'", "");

					String rc = details[10];
					rc = rc.replace("'", "");

					String o = details[11];
					o = o.replace("'", "");

					String u = details[12];
					u = u.replace("'", "");

					String oh = details[13]; // 小球赔率
					oh = oh.replace("'", "");

					String oc = details[14];// 大球赔率
					oc = oc.replace("'", "");

					// 半场 start index 20

					String hgid = details[20];
					hgid = hgid.replace("'", "");

					String hstrong = details[21];
					hstrong = hstrong.replace("'", "");

					String hpankou = details[22];
					hpankou = hpankou.replace("'", "");

					String hrh = details[23]; // 主队赔率
					hrh = hrh.replace("'", "");

					String hrc = details[24]; // 客队赔率
					hrc = hrc.replace("'", "");

					String ho = details[25];
					ho = ho.replace("'", "");

					String hu = details[26];
					hu = hu.replace("'", "");

					String hoh = details[27]; // 小球赔率
					hoh = hoh.replace("'", "");

					String hoc = details[28]; // 大球赔率
					hoc = hoc.replace("'", "");

					if (pankou.equals("") && hpankou.equals("") && o.equals("") && ho.equals("")) {
						bignore = true;
					}

					if (bignore == false) {

						HGEvent hgEvent = new HGEvent();

						hgEvent.eventId = eventid;
						hgEvent.gid = gid;
						hgEvent.leagueName = league;
						hgEvent.homeTeam = teamh;
						hgEvent.awayTeam = teamc;
						hgEvent.homeTeamScore = scoreh;
						hgEvent.awayTeamScore = scorec;
						hgEvent.eventTime = datetime;
						hgEvent.duringTime = timer;
						hgEvent.gnumh = gnumh;
						hgEvent.gnumc = gnumc;
						hgEvent.wholeRQPPankou = Common.pankouStr(strong + pankou);
						hgEvent.strong = strong;
						hgEvent.hstrong = hstrong;
						hgEvent.wholeRQPPankouUp = rh;
						hgEvent.wholeRQPPankouDown = rc;
						hgEvent.wholeDXPPankou = Common.pankouStr(o);
						hgEvent.wholeDXPPankouUp = oc;
						hgEvent.wholeDXPPankouDown = oh;
						hgEvent.hgid = hgid;
						hgEvent.halfRQPPankou = Common.pankouStr(hstrong + hpankou);
						hgEvent.halfRQPPankouUp = hrh;
						hgEvent.halfRQPPankouDown = hrc;
						hgEvent.halfDXPPankou = Common.pankouStr(ho);
						hgEvent.halfDXPPankouUp = hoc;
						hgEvent.halfDXPPankouDown = hoh;

						if ((Common.isNum(redcardh) && Integer.parseInt(redcardh) > 0)
								|| (Common.isNum(redcardc) && Integer.parseInt(redcardc) > 0)) {

							System.out
									.println(df.format(System.currentTimeMillis()) + teamh + "-vs-" + teamc + "红牌!!!");

							RedcardsRecords redcardsRecord = new RedcardsRecords();
							redcardsRecord.gnumh = gnumh;
							redcardsRecord.gnumc = gnumc;
							redcardsRecord.redcardh = redcardh;
							redcardsRecord.redcardc = redcardc;
							HGManager.redcardsRecords.add(redcardsRecord);
						}
					}

					// 下一场
					ps = res.indexOf("g([", pe);

					if (ps == -1) {

						break;
					}

					ps = ps + 3;

					pe = res.indexOf(";", ps);

					previousgame = currentgame;

				}

				ps = res.indexOf("t_page");
				ps = res.indexOf("=", ps) + 1;
				pe = res.indexOf(";", ps);

				int totalpage = Integer.parseInt(res.substring(ps, pe));

				for (int page = 1; page < totalpage; page++) {

					// Thread.sleep(200);

					res = doGet(ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re_main"
							+ "&langx=zh-cn" + "&mtype=" + mtype + "&page_no=" + Integer.toString(page)
							+ "&league_id=&hot_game=" + "&isie11=%27N%27", "", "");

					// 解析工作 第i页
					// res = bala...

					if (res == null || !res.contains("g([")) {
						res = doGet(ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re_main"
								+ "&langx=zh-cn" + "&mtype=" + mtype + "&page_no=" + Integer.toString(page)
								+ "&league_id=&hot_game=" + "&isie11=%27N%27", "", "");
					}

					if (null != res && res.contains("g([")) {

						if (res.contains("è")) {
							res = new String(res.getBytes("ISO-8859-1"), "utf-8");
						}

						// System.out.println(res);

						ps = res.indexOf("g([") + 3;
						pe = res.indexOf(";", ps);

						while (ps != -1) {

							boolean bignore = false;

							String[] details = res.substring(ps, pe).split(",");

							if (details.length < 57) {
								System.out.println("funck length small than 57");
							}

							String eventid = details[50];
							eventid = eventid.replace("'", "");

							currentgame = eventid;

							if (!currentgame.equals(previousgame)) {
								priority = 1;
							} else {
								priority = priority + 1;
								bignore = true;
							}

							String scoreh = details[18];
							scoreh = scoreh.replace("'", "");

							String scorec = details[19];
							scorec = scorec.replace("'", "");

							String timer = details[48];
							timer = timer.replace("'", "");

							timer = timer.replace("^", " ");

							if (timer.contains("半场")) {
								timer = "半场";
							}

							String gid = details[0]; // 标识一个盘口的
							gid = gid.replace("'", "");

							String datetime = details[1];
							datetime = datetime.replace("'", "");
							datetime = datetime.replace("<br>", " ");

							if (datetime.contains("半场")) {
								datetime = "半场";
							}

							String league = details[2];
							league = league.replace("'", "");

							if (league.contains("特别投注")) {
								bignore = true;
							}

							String gnumh = details[3];
							gnumh = gnumh.replace("'", "");

							String gnumc = details[4];
							gnumc = gnumc.replace("'", "");

							String teamh = details[5];
							teamh = teamh.replace("'", "");
							teamh = teamh.replace(" [中]", "");

							if (teamh.contains("角球数") || teamh.contains("罚牌数")) {

								bignore = true;
							}

							String teamc = details[6];
							teamc = teamc.replace("'", "");

							// 全场
							String strong = details[7];
							strong = strong.replace("'", "");

							String pankou = details[8];
							pankou = pankou.replace("'", "");

							String rh = details[9];
							rh = rh.replace("'", "");

							String rc = details[10];
							rc = rc.replace("'", "");

							String o = details[11];
							o = o.replace("'", "");

							String u = details[12];
							u = u.replace("'", "");

							String oh = details[13]; // 小球赔率
							oh = oh.replace("'", "");

							String oc = details[14];// 大球赔率
							oc = oc.replace("'", "");

							// 半场 start index 20

							String hgid = details[20];
							hgid = hgid.replace("'", "");

							String hstrong = details[21];
							hstrong = hstrong.replace("'", "");

							String hpankou = details[22];
							hpankou = hpankou.replace("'", "");

							String hrh = details[23]; // 主队赔率
							hrh = hrh.replace("'", "");

							String hrc = details[24]; // 客队赔率
							hrc = hrc.replace("'", "");

							String ho = details[25];
							ho = ho.replace("'", "");

							String hu = details[26];
							hu = hu.replace("'", "");

							String hoh = details[27]; // 小球赔率
							hoh = hoh.replace("'", "");

							String hoc = details[28]; // 大球赔率
							hoc = hoc.replace("'", "");

							if (pankou.equals("") && hpankou.equals("") && o.equals("") && ho.equals("")) {
								bignore = true;
							}

							if (bignore == false) {
								HGEvent hgEvent = new HGEvent();

								hgEvent.eventId = eventid;
								hgEvent.gid = gid;
								hgEvent.leagueName = league;
								hgEvent.homeTeam = teamh;
								hgEvent.awayTeam = teamc;
								hgEvent.homeTeamScore = scoreh;
								hgEvent.awayTeamScore = scorec;
								hgEvent.eventTime = datetime;
								hgEvent.duringTime = timer;
								hgEvent.gnumh = gnumh;
								hgEvent.gnumc = gnumc;
								hgEvent.wholeRQPPankou = Common.pankouStr(strong + pankou);
								hgEvent.wholeRQPPankouUp = rh;
								hgEvent.wholeRQPPankouDown = rc;
								hgEvent.wholeDXPPankou = Common.pankouStr(o);
								hgEvent.wholeDXPPankouUp = oc;
								hgEvent.wholeDXPPankouDown = oh;
								hgEvent.hgid = hgid;
								hgEvent.halfRQPPankou = Common.pankouStr(hstrong + hpankou);
								hgEvent.halfRQPPankouUp = hrh;
								hgEvent.halfRQPPankouDown = hrc;
								hgEvent.halfDXPPankou = Common.pankouStr(ho);
								hgEvent.halfDXPPankouUp = hoc;
								hgEvent.halfDXPPankouDown = hoh;

							}

							// 下一场
							ps = res.indexOf("g([", pe);

							if (ps == -1) {

								break;
							}

							ps = ps + 3;

							pe = res.indexOf(";", ps);

							previousgame = currentgame;

						}

					}

				}

			}

			return true;

		} catch (Exception e) {
			e.printStackTrace();

			updateStatusCode(3);

			addFailsTimes();
			return false;
		}

	}

	public Map<String, String> getInplaybetScores() {

		try {

			Map<String, String> map = new HashMap<String, String>();

			if (statusCode == -1 || statusCode == -2 || statusCode == -3 || statusCode == -4) {
				return map;
			}

			String res = "";

			res = doGet(ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re" + "&langx=zh-cn"
					+ "&mtype=" + mtype + "&page_no=0" + "&league_id=&hot_game=" + "&isie11=%27N%27", "", "");

			if (res == null) {

				Thread.currentThread();
				Thread.sleep(4 * 1000);

				res = doGet(
						ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re" + "&langx=zh-cn"
								+ "&mtype=" + mtype + "&page_no=0" + "&league_id=&hot_game=" + "&isie11=%27N%27",
						"", "");
			}

			if (res == null) {
				addFailsTimes();
				return null;
			}

			// System.out.println(res);

			if (res.contains("logout_warn")) {

				System.out.println("inplay contains logout_warn");

				setIsNeedRelogin(true);

				return null;

			}

			String previousgame = "";

			String currentgame = "";

			int priority = -1;

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式

			long currentTimeL = System.currentTimeMillis();

			String currentTime = df.format(currentTimeL);

			if (null != res && res.contains("g([")) {

				// 解析工作 第一页
				// res = bala...

				if (res.contains("è")) {
					res = new String(res.getBytes("ISO-8859-1"), "utf-8");
				}

				// int ps = res.indexOf("_.gamount=");
				int ps = res.indexOf("today_gmt");
				ps = res.indexOf("'", ps) + 1;
				int pe = res.indexOf("'", ps);

				String year = res.substring(ps, pe).split("-")[0];

				// ps = res.indexOf(arg0)

				ps = res.indexOf("g([") + 3;
				pe = res.indexOf(";", ps);

				// System.out.println(res);

				SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd HH:mm");

				while (ps != -1) {

					boolean bignore = false;

					String[] details = res.substring(ps, pe).split(",");

					if (details.length < 57) {
						System.out.println("fuck length small than 57");
					}

					String eventid = details[50];
					eventid = eventid.replace("'", "");

					currentgame = eventid;

					// if(!currentgame.equals(previousgame)){
					// priority = 1;
					// }else{
					// priority = priority + 1;
					// bignore = true;
					// }

					String scoreh = details[18];
					scoreh = scoreh.replace("'", "");

					String scorec = details[19];
					scorec = scorec.replace("'", "");

					String timer = details[48];
					timer = timer.replace("'", "");

					timer = timer.replace("^", " ");

					if (timer.contains("半场")) {
						timer = "半场";
					}

					String gid = details[0]; // 标识一个盘口的
					gid = gid.replace("'", "");

					String datetime = details[1];
					datetime = datetime.replace("'", "");
					datetime = datetime.replace("<br>", " ");

					if (datetime.contains("半场")) {
						datetime = "半场";
					}

					String league = details[2];
					league = league.replace("'", "");

					if (league.contains("-附加赛")) {
						league = league.replace("-附加赛", "");
					}

					if (league.contains("特别投注")) {
						bignore = true;
					}

					String gnumh = details[3];
					gnumh = gnumh.replace("'", "");

					String gnumc = details[4];
					gnumc = gnumc.replace("'", "");

					String teamh = details[5];
					teamh = teamh.replace("'", "");
					teamh = teamh.replace(" [中]", "");

					if (teamh.contains("角球数") || teamh.contains("罚牌数")) {

						bignore = true;
					}

					String teamc = details[6];
					teamc = teamc.replace("'", "");

					// 全场
					String strong = details[7];
					strong = strong.replace("'", "");

					String pankou = details[8];
					pankou = pankou.replace("'", "");

					String rh = details[9];
					rh = rh.replace("'", "");

					String rc = details[10];
					rc = rc.replace("'", "");

					String o = details[11];
					o = o.replace("'", "");

					String u = details[12];
					u = u.replace("'", "");

					String oh = details[13]; // 小球赔率
					oh = oh.replace("'", "");

					String oc = details[14];// 大球赔率
					oc = oc.replace("'", "");

					// 半场 start index 20

					String hgid = details[20];
					hgid = hgid.replace("'", "");

					String hstrong = details[21];
					hstrong = hstrong.replace("'", "");

					String hpankou = details[22];
					hpankou = hpankou.replace("'", "");

					String hrh = details[23]; // 主队赔率
					hrh = hrh.replace("'", "");

					String hrc = details[24]; // 客队赔率
					hrc = hrc.replace("'", "");

					String ho = details[25];
					ho = ho.replace("'", "");

					String hu = details[26];
					hu = hu.replace("'", "");

					String hoh = details[27]; // 小球赔率
					hoh = hoh.replace("'", "");

					String hoc = details[28]; // 大球赔率
					hoc = hoc.replace("'", "");

					if (pankou.equals("") && hpankou.equals("") && o.equals("") && ho.equals("")) {
						bignore = true;
					}

					if (bignore == false) {

						HGEvent hgEvent = new HGEvent();

						map.put(eventid, scoreh + ":" + scorec);

						hgEvent.eventId = eventid;
						hgEvent.gid = gid;
						hgEvent.leagueName = league;
						hgEvent.homeTeam = teamh;
						hgEvent.awayTeam = teamc;
						hgEvent.homeTeamScore = scoreh;
						hgEvent.awayTeamScore = scorec;
						hgEvent.eventTime = datetime;
						hgEvent.duringTime = timer;
						hgEvent.gnumh = gnumh;
						hgEvent.gnumc = gnumc;
						// hgEvent.wholerqppankou = Common.pankouStr(strong + pankou);
						hgEvent.strong = strong;
						hgEvent.hstrong = hstrong;
						hgEvent.wholeRQPPankouUp = rh;
						hgEvent.wholeRQPPankouDown = rc;
						// hgEvent.wholeDXPPankou = Common.pankouStr(o);
						hgEvent.wholeDXPPankouUp = oc;
						hgEvent.wholeDXPPankouDown = oh;
						hgEvent.hgid = hgid;
						// hgEvent.halfrqppankou = Common.pankouStr(hstrong + hpankou);
						hgEvent.halfRQPPankouUp = hrh;
						hgEvent.halfRQPPankouDown = hrc;
						// hgEvent.halfDXPPankou = Common.pankouStr(ho);
						hgEvent.halfDXPPankouUp = hoc;
						hgEvent.halfDXPPankouDown = hoh;

						// HGManager.HGEvents.add(hgEvent);

					}

					// 下一场
					ps = res.indexOf("g([", pe);

					if (ps == -1) {

						break;
					}

					ps = ps + 3;

					pe = res.indexOf(";", ps);

					previousgame = currentgame;

				}

				ps = res.indexOf("t_page");
				ps = res.indexOf("=", ps) + 1;
				pe = res.indexOf(";", ps);

				int totalpage = Integer.parseInt(res.substring(ps, pe));

				for (int page = 1; page < totalpage; page++) {

					// Thread.sleep(200);

					res = doGet(ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re_main"
							+ "&langx=zh-cn" + "&mtype=" + mtype + "&page_no=" + Integer.toString(page)
							+ "&league_id=&hot_game=" + "&isie11=%27N%27", "", "");

					// 解析工作 第i页
					// res = bala...

					if (res == null || !res.contains("g([")) {
						res = doGet(ADDRESS + "app/member/FT_browse/body_var.php?" + "uid=" + user_id + "&rtype=re_main"
								+ "&langx=zh-cn" + "&mtype=" + mtype + "&page_no=" + Integer.toString(page)
								+ "&league_id=&hot_game=" + "&isie11=%27N%27", "", "");
					}

					if (null != res && res.contains("g([")) {

						if (res.contains("è")) {
							res = new String(res.getBytes("ISO-8859-1"), "utf-8");
						}

						// System.out.println(res);

						ps = res.indexOf("g([") + 3;
						pe = res.indexOf(";", ps);

						while (ps != -1) {

							boolean bignore = false;

							String[] details = res.substring(ps, pe).split(",");

							if (details.length < 57) {
								System.out.println("funck length small than 57");
							}

							String eventid = details[50];
							eventid = eventid.replace("'", "");

							currentgame = eventid;

							if (!currentgame.equals(previousgame)) {
								priority = 1;
							} else {
								priority = priority + 1;
								bignore = true;
							}

							String scoreh = details[18];
							scoreh = scoreh.replace("'", "");

							String scorec = details[19];
							scorec = scorec.replace("'", "");

							String timer = details[48];
							timer = timer.replace("'", "");

							timer = timer.replace("^", " ");

							if (timer.contains("半场")) {
								timer = "半场";
							}

							String gid = details[0]; // 标识一个盘口的
							gid = gid.replace("'", "");

							String datetime = details[1];
							datetime = datetime.replace("'", "");
							datetime = datetime.replace("<br>", " ");

							if (datetime.contains("半场")) {
								datetime = "半场";
							}

							String league = details[2];
							league = league.replace("'", "");

							if (league.contains("特别投注")) {
								bignore = true;
							}

							String gnumh = details[3];
							gnumh = gnumh.replace("'", "");

							String gnumc = details[4];
							gnumc = gnumc.replace("'", "");

							String teamh = details[5];
							teamh = teamh.replace("'", "");
							teamh = teamh.replace(" [中]", "");

							if (teamh.contains("角球数") || teamh.contains("罚牌数")) {

								bignore = true;
							}

							String teamc = details[6];
							teamc = teamc.replace("'", "");

							// 全场
							String strong = details[7];
							strong = strong.replace("'", "");

							String pankou = details[8];
							pankou = pankou.replace("'", "");

							String rh = details[9];
							rh = rh.replace("'", "");

							String rc = details[10];
							rc = rc.replace("'", "");

							String o = details[11];
							o = o.replace("'", "");

							String u = details[12];
							u = u.replace("'", "");

							String oh = details[13]; // 小球赔率
							oh = oh.replace("'", "");

							String oc = details[14];// 大球赔率
							oc = oc.replace("'", "");

							// 半场 start index 20

							String hgid = details[20];
							hgid = hgid.replace("'", "");

							String hstrong = details[21];
							hstrong = hstrong.replace("'", "");

							String hpankou = details[22];
							hpankou = hpankou.replace("'", "");

							String hrh = details[23]; // 主队赔率
							hrh = hrh.replace("'", "");

							String hrc = details[24]; // 客队赔率
							hrc = hrc.replace("'", "");

							String ho = details[25];
							ho = ho.replace("'", "");

							String hu = details[26];
							hu = hu.replace("'", "");

							String hoh = details[27]; // 小球赔率
							hoh = hoh.replace("'", "");

							String hoc = details[28]; // 大球赔率
							hoc = hoc.replace("'", "");

							if (pankou.equals("") && hpankou.equals("") && o.equals("") && ho.equals("")) {
								bignore = true;
							}

							if (bignore == false) {
								HGEvent hgEvent = new HGEvent();

								map.put(eventid, scoreh + ":" + scorec);

								hgEvent.eventId = eventid;
								hgEvent.gid = gid;
								hgEvent.leagueName = league;
								hgEvent.homeTeam = teamh;
								hgEvent.awayTeam = teamc;
								hgEvent.homeTeamScore = scoreh;
								hgEvent.awayTeamScore = scorec;
								hgEvent.eventTime = datetime;
								hgEvent.duringTime = timer;
								hgEvent.gnumh = gnumh;
								hgEvent.gnumc = gnumc;
								// hgEvent.wholerqppankou = Common.pankouStr(strong + pankou);
								hgEvent.wholeRQPPankouUp = rh;
								hgEvent.wholeRQPPankouDown = rc;
								// hgEvent.wholeDXPPankou = Common.pankouStr(o);
								hgEvent.wholeDXPPankouUp = oc;
								hgEvent.wholeDXPPankouDown = oh;
								hgEvent.hgid = hgid;
								// hgEvent.halfrqppankou = Common.pankouStr(hstrong + hpankou);
								hgEvent.halfRQPPankouUp = hrh;
								hgEvent.halfRQPPankouDown = hrc;
								// hgEvent.halfDXPPankou = Common.pankouStr(ho);
								hgEvent.halfDXPPankouUp = hoc;
								hgEvent.halfDXPPankouDown = hoh;

								// HGManager.HGEvents.add(hgEvent);
							}

							// 下一场
							ps = res.indexOf("g([", pe);

							if (ps == -1) {

								break;
							}

							ps = ps + 3;

							pe = res.indexOf(";", ps);

							previousgame = currentgame;

						}

					}

				}

			}

			return map;

		} catch (Exception e) {
			e.printStackTrace();

			updateStatusCode(3);

			addFailsTimes();
			return null;
		}

	}

	/*
	 * 
	 */
	public Map<String, String> updateRatio(String gid, String type, String gnum, String strong, String rtype,
			String wtype) {

		String res = "";

		try {
			
        	List<NameValuePair> orderViewParams = new ArrayList<NameValuePair>();
        	orderViewParams.add(new BasicNameValuePair("p", "FT_order_view"));
        	orderViewParams.add(new BasicNameValuePair("uid", uid));
        	orderViewParams.add(new BasicNameValuePair("gid", gid));
        	orderViewParams.add(new BasicNameValuePair("ver", ver));
        	orderViewParams.add(new BasicNameValuePair("langx", "zh-cn"));
        	orderViewParams.add(new BasicNameValuePair("odd_f_type", "M"));
        	orderViewParams.add(new BasicNameValuePair("gtype", "FT"));
        	orderViewParams.add(new BasicNameValuePair("wtype", wtype));
        	orderViewParams.add(new BasicNameValuePair("chose_team", type));//H或者C type给过来就是choose team        	
        	String url  = ADDRESS + "transform.php?ver=" + ver;
			res = doPost(url, orderViewParams, "");

			Map<String, String> map = new HashMap<String, String>();
			int requestCount = 0;
			if(requestCount<3&&res==null) {
				res = doPost(url, orderViewParams, "");
			}
			
			if(res==null) {
				Common.logOut("updateRatio 获取res为空");
				return null;
			}
			
			if(res.contains("gold_gmax")) {
				Document orderViewDoc = Jsoup.parse(res);

				
				String con = orderViewDoc.selectFirst("con").ownText();
				String ioratio = orderViewDoc.selectFirst("ioratio").ownText(); //这个是水位
				String ratio = orderViewDoc.selectFirst("ratio").ownText();
				String timestamp2 = orderViewDoc.selectFirst("ts").ownText();
				String pankou = orderViewDoc.selectFirst("spread").ownText().replace(" ", "");
				if(strong.equals("C")) {
					pankou = Double.toString(0.0 - Common.pankouDouble(pankou));
				}else {
					pankou = Double.toString(Common.pankouDouble(pankou));
				}
				String minbet = orderViewDoc.selectFirst("gold_gmin").ownText();
				String maxbet = orderViewDoc.selectFirst("gold_gmax").ownText();
				
				map.put("con", con);
				map.put("ioratio", ioratio);
				map.put("ratio", ratio);
				map.put("timestamp2", timestamp2);
				map.put("pankou", pankou);
				map.put("minbet", minbet);
				map.put("maxbet", maxbet);
				return map;
				
			}
			
//
//			if (strong.equals("")) {
//
//				url = ADDRESS + "app/member/FT_order/FT_order_all.php?gid=" + gid + "&uid=" + user_id
//						+ "&odd_f_type=M&type=" + type + "&gnum=" + gnum + "&langx=zh-cn&ptype=&imp=N&rtype=" + rtype
//						+ "&wtype=" + wtype;
//
//			} else {
//				url = ADDRESS + "app/member/FT_order/FT_order_all.php?gid=" + gid + "&uid=" + user_id
//						+ "&odd_f_type=M&type=" + type + "&gnum=" + gnum + "&strong=" + strong
//						+ "&langx=zh-cn&ptype=&imp=N&rtype=" + rtype + "&wtype=" + wtype;
//			}
//
//			res = doGet(url, "", "");
//			
//       	 Document doc1 = Jsoup.parse(res);
//       	 Element form = doc1.getElementById("newdomain");
//       	 if(form!=null) {
//       		 ADDRESS =  form.attr("action") + "/";
//       		 
// 			if (strong.equals("")) {
//
//				url = ADDRESS + "app/member/FT_order/FT_order_all.php?gid=" + gid + "&uid=" + user_id
//						+ "&odd_f_type=M&type=" + type + "&gnum=" + gnum + "&langx=zh-cn&ptype=&imp=N&rtype=" + rtype
//						+ "&wtype=" + wtype;
//
//			} else {
//				url = ADDRESS + "app/member/FT_order/FT_order_all.php?gid=" + gid + "&uid=" + user_id
//						+ "&odd_f_type=M&type=" + type + "&gnum=" + gnum + "&strong=" + strong
//						+ "&langx=zh-cn&ptype=&imp=N&rtype=" + rtype + "&wtype=" + wtype;
//			}
//
//			res = doGet(url, "", "");
//       		 
//       	 }
//
//			
//
//			if (res == null) {
//				res = doGet(url, "", "");
//			}
//
//			if (res.contains("dafa008")) {
//
//				System.out.println("Enter dafa");
//
//				res = doGet(url, "", "");
//			}
//
//			if (res.contains("è")) {
//				res = new String(res.getBytes("ISO-8859-1"), "utf-8");
//			}
//
//			if (res.contains("确定交易")) {
//
//				Document doc = Jsoup.parse(res);
//
//				String divID = "model_" + wtype;
//
//				Element div = doc.getElementById(divID);
//
//				String pankou = div.getElementsByClass("fatWord").first().html();
//
//				if (pankou.equals("")) {
//					pankou = div.getElementsByClass("fatWord").last().html();
//
//					pankou = Double.toString(0.0 - Common.pankouDouble(pankou));
//
//				} else {
//					pankou = Double.toString(Common.pankouDouble(pankou));
//				}
//
//				String ratio = div.getElementsByClass("redFatWord").first().html();
//
//				map.put("pankou", pankou);
//				map.put("ratio", ratio);
//
//				div = doc.getElementsByClass("ord_TotalAreaG").first();
//
//				String minbet = div.getElementsByClass("Word_Toright").first().html();
//				String maxbet = div.getElementsByClass("Word_Toright").last().html();
//
//				map.put("minbet", minbet);
//				map.put("maxbet", maxbet);
//
//				// bet needed
//
//				String autoOdd = doc.selectFirst("input[name=autoOdd]").val();
//
//				String uid = doc.selectFirst("input[name=uid]").val();
//				String langx = doc.selectFirst("input[name=langx]").val();
//				String active = doc.selectFirst("input[name=active]").val();
//				String line_type = doc.selectFirst("input[name=line_type]").val();
//				String gid1 = doc.selectFirst("input[name=gid]").val();
//				String type1 = doc.selectFirst("input[name=type]").val();
//				String gnum1 = doc.selectFirst("input[name=gnum]").val();
//				String concede = doc.selectFirst("input[name=concede]").val();
//				String radio = doc.selectFirst("input[name=radio]").val();
//				String ioradio = doc.selectFirst("input[name=ioradio]").val();
//				String gmax_single = doc.selectFirst("input[name=gmax_single]").val();
//				String gmin_single = doc.selectFirst("input[name=gmin_single]").val();
//				String singlecredit = doc.selectFirst("input[name=singlecredit]").val();
//				String singleorder = doc.selectFirst("input[name=singleorder]").val();
//				String restsinglecredit = doc.selectFirst("input[name=restsinglecredit]").val();
//				String wagerstotal = doc.selectFirst("input[name=wagerstotal]").val();
//				String restcredit = doc.selectFirst("input[name=restcredit]").val();
//				String pay_type = doc.selectFirst("input[name=pay_type]").val();
//				String odd_f_type = doc.selectFirst("input[name=odd_f_type]").val();
//				String wtype1 = doc.selectFirst("input[name=wtype]").val();
//				String rtype1 = doc.selectFirst("input[name=rtype]").val();
//				String gametype = doc.selectFirst("input[name=gametype]").val();
//				String imp = doc.selectFirst("input[name=imp]").val();
//				String ptype = doc.selectFirst("input[name=ptype]").val();
//				String timestamp2 = doc.selectFirst("input[name=timestamp2]").val();
//
//				gametype = URLEncoder.encode(gametype, "UTF-8");
//
//				String betParam = "&autoOdd=Y&uid=" + uid + "&langx=zh-cn&active=" + active + "&line_type=" + line_type
//						+ "&gid=" + gid1 + "&type=" + type1 + "&gnum=" + gnum1 + "&concede=" + concede + "&radio="
//						+ radio + "&ioradio=" + ioradio + "&gmax_single=" + gmax_single + "&gmin_single=" + gmin_single
//						+ "&singlecredit=" + singlecredit + "&singleorder=" + singleorder + "&restsinglecredit="
//						+ restsinglecredit + "&wagerstotal=" + wagerstotal + "&restcredit=" + restcredit + "&pay_type="
//						+ pay_type + "&odd_f_type=" + odd_f_type + "&wtype=" + wtype1 + "&rtype=" + rtype1
//						+ "&gametype=" + gametype + "&=10&imp=N&ptype=&timestamp2=" + timestamp2 + "&timestamp="
//						+ Long.toString(System.currentTimeMillis());
//
//				map.put("betParam", betParam);
//
//				return map;
//			}
//
//			System.out.println("更新  HG Ratio失败" + res);

			return null;

		} catch (Exception e) {
			e.printStackTrace();

			System.out.println("更新  PS38 Ratio失败" + res);
		}

		return null;
	}

	public Map<String, String> doBet(Map<String,String> betParam, int gold) {

		String res = "";

		Map<String, String> resmap = new HashMap<String, String>();

		try {
			
        	List<NameValuePair> betParams = new ArrayList<NameValuePair>();
        	betParams.add(new BasicNameValuePair("p", "FT_bet"));
        	betParams.add(new BasicNameValuePair("uid", uid));
        	betParams.add(new BasicNameValuePair("ver", ver));
        	betParams.add(new BasicNameValuePair("langx", "zh-cn"));
        	betParams.add(new BasicNameValuePair("gid", betParam.get("gid")));
        	betParams.add(new BasicNameValuePair("odd_f_type", "M"));
        	betParams.add(new BasicNameValuePair("gtype", "FT"));
        	betParams.add(new BasicNameValuePair("golds", Integer.toString(gold)));
        	betParams.add(new BasicNameValuePair("chose_team", betParam.get("typestr")));//H或者C type给过来就是choose team  
        	betParams.add(new BasicNameValuePair("wtype", betParam.get("wtypestr")));
        	betParams.add(new BasicNameValuePair("rtype", betParam.get("wtypestr") + betParam.get("typestr")));
        	betParams.add(new BasicNameValuePair("ioratio", betParam.get("ioratio")));
        	betParams.add(new BasicNameValuePair("ratio", betParam.get("ratio")));
        	betParams.add(new BasicNameValuePair("con", betParam.get("con")));
        	betParams.add(new BasicNameValuePair("autoOdd", "Y"));
        	betParams.add(new BasicNameValuePair("isRB", "N"));
        	betParams.add(new BasicNameValuePair("imp", "N"));
        	betParams.add(new BasicNameValuePair("ptype", ""));
        	betParams.add(new BasicNameValuePair("isYesterday", "N"));
        	betParams.add(new BasicNameValuePair("timestamp",  Long.toString(System.currentTimeMillis()) ));
        	betParams.add(new BasicNameValuePair("timestamp2", betParam.get("timestamp2")));
        	betParams.add(new BasicNameValuePair("f", "1R"));
        	
        	String url  = ADDRESS + "transform.php?ver=" + ver;
			res = doPost(url, betParams, "");
			
			if(res==null) {
				res = doPost(url, betParams, "");
			}

			if(res==null) {
				addFailsTimes();
				return null;
			}
			
			SimpleDateFormat dfSec = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			if (res.contains("è")) {
				res = new String(res.getBytes("ISO-8859-1"), "utf-8");
			}
			

			if (res.contains("code")) {

		       	 Document doc = Jsoup.parse(res);		       	
				if(doc.selectFirst("code").ownText().equals("560")) {
					String betteam = "";
					if(doc.selectFirst("wtype").ownText().equals("R")) {
						if(doc.selectFirst("type").ownText().equals("H")) {
							betteam = doc.selectFirst("team_h").ownText();
						}else {
							betteam = doc.selectFirst("team_c").ownText();
						}
					}else {
						if(doc.selectFirst("type").ownText().equals("H")) {
							betteam = "小";
						}else {
							betteam = "大";
						}
					}
					
					String pankou = doc.selectFirst("spread").ownText();
					Long bettime = Long.parseLong(doc.selectFirst("timestamp").ownText());
					
					if(doc.selectFirst("wtype").ownText().equals("R")) {
						if(betParam.get("strong").equals("C")) {
							pankou = Double.toString(0.0 - Common.pankouDouble(pankou));
						}else {
							pankou = Double.toString(Common.pankouDouble(pankou));
						}						
					}else {
						pankou = Double.toString(Common.pankouDouble(pankou));
					}
					
					String ticketid = doc.selectFirst("ticket_id").ownText();
					
					
					resmap.put("betteam", betteam);
					resmap.put("betpankou", pankou);
					resmap.put("betratio", doc.selectFirst("ioratio").ownText());
					resmap.put("ticketid", ticketid);
					resmap.put("bettime", dfSec.format(System.currentTimeMillis()));
					resmap.put("status", "1");
					NegativeRatioClient.betCtrMng.lastbetsuccesstime = System.currentTimeMillis();
					return resmap;
				}else if(doc.selectFirst("code").ownText().equals("555") &&
						doc.selectFirst("errormsg").ownText().equals("1X012")) {
					resmap.put("status", "-1");
		        	
				}else if(doc.selectFirst("code").ownText().equals("555") &&
						doc.selectFirst("errormsg").ownText().equals("1X008")) {
					resmap.put("status", "-4");
		        	
				}else {
					resmap.put("status", "-2");
				}



				return resmap;


			}

		} catch (Exception e) {
			e.printStackTrace();
		}



//		if (res.contains("不可大于股东单场总信用额度")) {
//			resmap.put("status", "-4");
//			return resmap;
//		}

		resmap.put("status", "-2");

		System.out.println("投注失败:" + res);

		return resmap;

	}

	public static void main(String[] args) {
		try {

			File file = new File("data/" + "html.txt");

			if (!file.exists()) {
				return;
			}

			BufferedReader freader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));

			Document doc = Jsoup.parse(file, "UTF-8", "https://www.baidu.com/");
			/*
			 * Element div = doc.getElementById("model_R");
			 * 
			 * Elements leaguename = div.getElementsByClass("upperWord"); String res =
			 * leaguename.first().html();
			 * 
			 * String pankou = div.getElementsByClass("fatWord").first().html();
			 * 
			 * String ratio = div.getElementsByClass("redFatWord").first().html();
			 * 
			 * 
			 * div = doc.getElementsByClass("ord_TotalAreaG").first();
			 * 
			 * String minbet = div.getElementsByClass("Word_Toright").first().html(); String
			 * maxbet = div.getElementsByClass("Word_Toright").last().html();
			 */

			/*
			 * String autoOdd = doc.selectFirst("input[name=autoOdd]").val();
			 * 
			 * String uid = doc.selectFirst("input[name=uid]").val(); String langx =
			 * doc.selectFirst("input[name=langx]").val(); String active =
			 * doc.selectFirst("input[name=active]").val(); String line_type =
			 * doc.selectFirst("input[name=line_type]").val(); String gid =
			 * doc.selectFirst("input[name=gid]").val(); String type =
			 * doc.selectFirst("input[name=type]").val(); String gnum =
			 * doc.selectFirst("input[name=gnum]").val(); String concede =
			 * doc.selectFirst("input[name=concede]").val(); String radio =
			 * doc.selectFirst("input[name=radio]").val(); String ioradio =
			 * doc.selectFirst("input[name=ioradio]").val(); String gmax_single =
			 * doc.selectFirst("input[name=gmax_single]").val(); String gmin_single =
			 * doc.selectFirst("input[name=gmin_single]").val(); String singlecredit =
			 * doc.selectFirst("input[name=singlecredit]").val(); String singleorder =
			 * doc.selectFirst("input[name=singleorder]").val(); String restsinglecredit =
			 * doc.selectFirst("input[name=restsinglecredit]").val(); String wagerstotal =
			 * doc.selectFirst("input[name=wagerstotal]").val(); String restcredit =
			 * doc.selectFirst("input[name=restcredit]").val(); String pay_type =
			 * doc.selectFirst("input[name=pay_type]").val(); String odd_f_type =
			 * doc.selectFirst("input[name=odd_f_type]").val(); String wtype =
			 * doc.selectFirst("input[name=wtype]").val(); String rtype =
			 * doc.selectFirst("input[name=rtype]").val(); String gametype =
			 * doc.selectFirst("input[name=gametype]").val(); String imp =
			 * doc.selectFirst("input[name=imp]").val(); String ptype =
			 * doc.selectFirst("input[name=ptype]").val(); String timestamp2 =
			 * doc.selectFirst("input[name=timestamp2]").val();
			 */

			String maxbet = URLEncoder.encode("560045132|884359660|0|2|1|0|1.75|0", "UTF-8");

			// String maxbet = Double.toHexString((Math.floor((1 + Math.random()) *
			// 65536)));

			// String hhe = maxbet.substring(1);

			// Map<String, String> jb = (Map<String, String>)getValue("{league=,
			// match=avsb}");
			// jb.put("league", "英超");
			// jb.put("match", "avsb");
			//
			// jb.toString();

			// System.out.println(jb.get("match"));
			// System.out.println(hhe);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getShowTodayRecURL() {

		// http://hga030.com/app/member/account/today_wagers.php?uid=qg3w277xom20694187l274422&langx=zh-cn&type=today_wagers

		return ADDRESS + "app/member/account/today_wagers.php?uid=" + user_id + "&langx=zh-cn&type=today_wagers";

		// String[] res = {ADDRESS + "app/member/account/get_today_wagers.php", "uid=" +
		// user_id +"&langx=zh-cn&chk_cw=N&page=1"};

		// return res;

	}

	public String getHistoryRecURL() {

		try {

			// return oldSiteAddress + "app/member/history/history_data.php?uid="+ user_id
			// +"&langx=zh-cn";

			// http://hga030.com/app/member/account/history_data.php?uid=r4hzv9dnpm20834322l243950&langx=zh-cn&type=history_data
			String url  = ADDRESS + "transform.php?ver=" + ver;
			return url;

		} catch (Exception e) {
			e.printStackTrace();

		}

		return "";
	}
	
	public String getHistoryRecPostData() {

		try {

			//p=history_data&ver=2021-07-26-23en18888b-MT04-ad68-0723-976ae5576be8&langx=zh-cn&uid=2h2dwi0zrm23496940l283544b0
			String postData = "p=history_data&ver="+ver +"&langx=zh-cn&uid=" +uid;
			return postData;
			//return ADDRESS + "app/member/account/history_data.php?uid=" + user_id + "&langx=zh-cn&type=history_data";

		} catch (Exception e) {
			e.printStackTrace();

		}

		return "";
	}

	public void reloadCredit() {

	}

	public void updatehgBetLogData(Vector<BetAdyData> betLogDatas) {
		// TODO Auto-generated method stub

		try {

			String url = ADDRESS + "app/member/get_order_mybet.php";

			List<NameValuePair> params = new ArrayList<NameValuePair>();

			params.add(new BasicNameValuePair("uid", user_id));
			params.add(new BasicNameValuePair("langx", "zh-cn"));
			params.add(new BasicNameValuePair("pgType", "10rec"));

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			String res = doPost(url, params, "");

			if (res == null) {
				res = doPost(url, params, "");
			}

			int ps = -1;
			int pe = -1;

			if (res != null && res.contains("betinfo")) {

				if (res.contains("è")) {
					res = new String(res.getBytes("ISO-8859-1"), "utf-8");
				}

				for (BetAdyData bd : betLogDatas) {

					if (bd.hgbetres.equals("0")) {
						String ticketid = bd.betAmount;

						ticketid = ticketid.replace("OU", "");

						ps = res.indexOf(ticketid);

						if (-1 == ps) {
							bd.hgbetres = "-1";
							continue;
						}

						ps = res.indexOf("betinfo", ps);
						ps = res.indexOf(">", ps) + 1;
						pe = res.indexOf("<", ps);

						String betres = res.substring(ps, pe);

						if (betres.equals("确认")) {
							bd.hgbetres = "2";

							System.out.println(df.format(System.currentTimeMillis()) + "  皇冠比赛确认:   " + bd.teams + "   "
									+ bd.betAmount);

							// System.out.println("betres= " + betres);

							// System.out.println("res = " + res);

						} else if (betres.contains("待确认")) {
							continue;
						} else if (betres.contains("投注失败")) {
							bd.hgbetres = "-3";

						}

					}

				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void checkIllealBet() {

		try {

			SimpleDateFormat df = new SimpleDateFormat("MM-dd HH:mm:ss");// 设置日期格式

			String uri = ADDRESS + "app/member/account/get_today_wagers.php";

			List<NameValuePair> params = new ArrayList<NameValuePair>();

			params.add(new BasicNameValuePair("uid", user_id));
			params.add(new BasicNameValuePair("langx", "zh-cn"));
			params.add(new BasicNameValuePair("chk_cw", "N"));
			params.add(new BasicNameValuePair("page", "1"));

			String res = doPost(uri, params, "");
			
	       	 Document doc1 = Jsoup.parse(res);
	       	 Element form = doc1.getElementById("newdomain");
	       	 if(form!=null) {
	       		 ADDRESS =  form.attr("action") + "/";
	       		 
	       		uri = ADDRESS + "app/member/account/get_today_wagers.php";

	       		res = doPost(uri, params, "");
	       		 
	       	 }

			if (res == null) {
				res = doPost(uri, params, "");
			}

			if (res == null) {
				return;
			}

			if (res != null && (res.contains("è")||res.contains("å")) ) {
				res = new String(res.getBytes("ISO-8859-1"), "utf-8");
			}

			int page = 0;

			if (res.contains("total_page")) {
				int ps = res.indexOf("total_page");
				ps = res.indexOf(">", ps) + 1;
				int pe = res.indexOf("<", ps);

				page = Integer.parseInt(res.substring(ps, pe));
				
				System.out.println(res);

				if (res.contains("非正常投注")) {
					System.out.println(df.format(System.currentTimeMillis()) + "存在非投，停止投注");

					NegativeRatioClient.hasIllegalBet = true;
					return;
				}
			}

			Thread.sleep(500);

			for (int i = 2; i <= page; i++) {

				List<NameValuePair> params1 = new ArrayList<NameValuePair>();

				params1.add(new BasicNameValuePair("uid", user_id));
				params1.add(new BasicNameValuePair("langx", "zh-cn"));
				params1.add(new BasicNameValuePair("chk_cw", "N"));
				params.add(new BasicNameValuePair("page", Integer.toString(i)));

				res = doPost(uri, params1, "");

				Thread.sleep(500);

				if (res != null && (res.contains("è")||res.contains("å")) ) {
					res = new String(res.getBytes("ISO-8859-1"), "utf-8");
				}

				if (res != null && res.contains("非正常投注")) {

					System.out.println(df.format(System.currentTimeMillis()) + "存在非投，停止投注");

					NegativeRatioClient.hasIllegalBet = true;
					return;

				}

			}
			
			
			
			
			
			
			//历史 
			//String hisUrl = 
			
			String hisUrl = ADDRESS + "app/member/account/history_data.php?uid="+user_id + "&langx=zh-cn&type=history_data";


			
			//app/member/account/history_data.php?uid=3v19ozrm23883938l147587b0&langx=zh-cn&type=history_data

			String hisRes = doGet(hisUrl, "", "");
			
	       	 Document hisDoc1 = Jsoup.parse(hisRes);
	       	 Element hisForm = doc1.getElementById("newdomain");
	       	 if(form!=null) {
	       		 ADDRESS =  hisForm.attr("action") + "/";
	       		 
	       		hisUrl = ADDRESS +"app/member/account/history_data.php?uid="+user_id + "&langx=zh-cn&type=history_data";

	       		hisRes = doGet(hisUrl, "", "");
	       		 
	       	 }

			if (hisRes == null) {
				hisRes = doGet(hisUrl, "", "");
			}

			if (hisRes == null) {
				return;
			}
			
			
			
			hisDoc1 = Jsoup.parse(hisRes);
			Elements hehe =  hisDoc1.getElementsByClass("acc_state_leftdate acc_tr_hand");
			Iterator it = hehe.iterator();
			
			while(it.hasNext()) {  
                Element element = (Element)it.next();
                String htmlStr = element.toString();
                int i1 = htmlStr.indexOf("today_gmt");
                i1 = htmlStr.indexOf("=",i1)+1;
                int i2 = htmlStr.indexOf("&",i1);
                String date = "";
                if(i1>0&&i2>0) {
                	date = htmlStr.substring(i1,i2);
                }
                
                if(htmlStr.contains("changeUrl")) {
                	String get_history_viewUrl = ADDRESS + "app/member/account/get_history_view.php";
                	
    				List<NameValuePair> params1 = new ArrayList<NameValuePair>();

    				params1.add(new BasicNameValuePair("uid", user_id));
    				params1.add(new BasicNameValuePair("langx", "zh-cn"));
    				params1.add(new BasicNameValuePair("today_gmt", date));
    				params1.add(new BasicNameValuePair("tmp_flag", "Y"));
    				params1.add(new BasicNameValuePair("gtype", "ALL"));
    				params1.add(new BasicNameValuePair("page", "1"));
    				
    				res = doPost(get_history_viewUrl, params1, "");
    				
    				if (res != null && (res.contains("è")||res.contains("å")) ) {
    					res = new String(res.getBytes("ISO-8859-1"), "utf-8");
    				}
    				

    				
    				if (res != null && res.contains("非正常投注")) {

    					System.out.println(df.format(System.currentTimeMillis()) + "存在非投，停止投注");

    					NegativeRatioClient.hasIllegalBet = true;
    					return;

    				}
    				
    				hisDoc1 = Jsoup.parse(res);
    				int totalPage = Integer.parseInt(hisDoc1.getElementsByTag("total_page").html());
    				for(int i = 2; i< totalPage;i++)
    				{
    					List<NameValuePair> params2 = new ArrayList<NameValuePair>();
        				params2.add(new BasicNameValuePair("uid", user_id));
        				params2.add(new BasicNameValuePair("langx", "zh-cn"));
        				params2.add(new BasicNameValuePair("today_gmt", date));
        				params2.add(new BasicNameValuePair("tmp_flag", "Y"));
        				params2.add(new BasicNameValuePair("gtype", "ALL"));
        				params2.add(new BasicNameValuePair("page", Integer.toString(i)));        				
        				res = doPost(get_history_viewUrl, params2, "");
        				
        				if (res != null && (res.contains("è")||res.contains("å")) ) {
        					res = new String(res.getBytes("ISO-8859-1"), "utf-8");
        				}

        				
        				if (res != null && res.contains("非正常投注")) {

        					System.out.println(df.format(System.currentTimeMillis()) + "存在非投，停止投注");

        					NegativeRatioClient.hasIllegalBet = true;
        					return;

        				}
    				}
                	
                }
            }  

			
			
			
			
			

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	
	
	
    public boolean getgameresult(){
    	try{
    		//https://205.201.2.225/app/member/account/result/result.php?game_type=FT&list_date=2022-03-14&uid=ih2hdrpm26912820l595489b0&langx=zh-cn
    		//https://205.201.2.225/app/member/account/result/result.php?game_type=FT&list_date=2022-03-15&uid=5adddxknfm26912820l595998b0&langx=zh-cn
    		
    		Long t1 = System.currentTimeMillis();
    		
    		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式    		    	
    		long currentTimeL = System.currentTimeMillis();
    		String list_date = df.format(currentTimeL);
    		String address = "http://205.201.2.225/app/member/account/result/result.php?game_type=FT&list_date=" + list_date + "&uid=" + uid + "&langx=zh-cn";
    		//String refer = "http://205.201.2.225/app/member/account/result/result.php?game_type=FT" + "&uid=" + uid + "&langx=zh-cn";
    		//当天数据
    		String res = doGet(address,"","");
    		
    		if(res!=null&& res.contains("acc_leftMain")) {
    			
    			NegativeRatioClient.betCtrMng.updateBetAdyGameResult(res);

    		}
    		
    		for(int i = 0; i < 3;i++) {//获取三天内的
    			currentTimeL = currentTimeL - 24*60*60*1000;
    			list_date = df.format(currentTimeL);
    			address = "http://205.201.2.225/app/member/account/result/result.php?game_type=FT&list_date=" + list_date + "&uid=" + uid + "&langx=zh-cn";
    			res = doGet(address,"","");
        		Thread.sleep(500);
        		if(res!=null&& res.contains("acc_leftMain")) {        			
        			NegativeRatioClient.betCtrMng.updateBetAdyGameResult(res);
        			
        		}else{
        			System.out.println("失败的res" + res);
        		}        		
    		}

    		System.out.println("更新比分所需要的时间是：");
    		
    		System.out.println(System.currentTimeMillis() - t1);
    		


    		return false;
    	}catch(Exception e){
    		addFailsTimes();
    		e.printStackTrace();
    		return false;
    	}
    }
	
	
	
	
	

	public void setCookie() {

		System.out.println(strCookies);

		Browser.setCookie("OddType@21916632=H", "http://hga030.com/");
		Browser.setCookie("gamePoint_21916632=2019-07-23%2A0%2A0", "http://hga030.com/");
		
	}

	public String getOutlineData() {
		// TODO Auto-generated method stub
		try {
			List<NameValuePair> historyParams = new ArrayList<NameValuePair>();
			historyParams.add(new BasicNameValuePair("p", "get_history_data"));
			historyParams.add(new BasicNameValuePair("uid", uid));
			historyParams.add(new BasicNameValuePair("langx", "zh-cn"));
			historyParams.add(new BasicNameValuePair("gtype", "FT"));
			historyParams.add(new BasicNameValuePair("isAll", "N"));
			
			String url  = ADDRESS + "transform.php?ver=" + ver;
			
			String res = doPost(url, historyParams, "");
			
			if(res==null) {
				res = doPost(url, historyParams, "");
			}
			
			if(res==null) {
				addFailsTimes();
				return null;
			}
			
			if(res.contains("è")||res.contains("ä")){
        		res = new  String(res.getBytes("ISO-8859-1"), "utf-8");
        	}
			
			if(res.contains("total_gold")) {
				return res;
			}
		}catch(Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	public String getDetailsData(String datetime) {
		try {
			List<NameValuePair> historyParams = new ArrayList<NameValuePair>();
			historyParams.add(new BasicNameValuePair("p", "get_history_view"));
			historyParams.add(new BasicNameValuePair("uid", uid));
			historyParams.add(new BasicNameValuePair("langx", "zh-cn"));
			historyParams.add(new BasicNameValuePair("LS", "c"));
			historyParams.add(new BasicNameValuePair("today_gmt", datetime));
			historyParams.add(new BasicNameValuePair("gtype", "FT"));
			historyParams.add(new BasicNameValuePair("tmp_flag", "Y"));
			
			String url  = ADDRESS + "transform.php?ver=" + ver;
			
			String res = doPost(url, historyParams, "");
			
			if(res==null) {
				res = doPost(url, historyParams, "");
			}
			
			if(res==null) {
				addFailsTimes();
				return null;
			}
			
			if(res.contains("è")||res.contains("ä")){
        		res = new  String(res.getBytes("ISO-8859-1"), "utf-8");
        	}
			
			if(res.contains("wagers")) {
				return res;
			}
		}catch(Exception e) {
			e.printStackTrace();
		}

		return null;
	}

}
